/**
 * @author tian qingsen
 */
$(function() {
	
	function validate() {
		var valiObj = $('#linkName');
		if (valiObj.length == 0 || valiObj.val() == '') {
			alert('请填写站点地址名称');
			valiObj.focus();
			return false;
		}
		
		valiObj = $('#linkUrl');
		if (valiObj.length == 0 || valiObj.val() == '') {
			alert('请填写站点URL');
			valiObj.focus();
			return false;
		}
		
		return true;
	}
	
	$('#save_btn').click(function(e) {
		
		if (!validate()) {
			return;
		}
		
		var url = window.ctx + '/admin/content/links_doadd.htm';
		if ($('#editFlag').length > 0) {
			url = window.ctx + '/admin/content/links_doedit.htm';
		}
		var data = $('#data_form').serializeArray();
		$.post(url, data, function(feedback) {
			if (feedback.successful) {
				if (confirm('保存成功，是否继续新增？')) {
					window.location.href = window.ctx + '/admin/content/links_edit.htm';
				} else {
					window.location.href = window.ctx + '/admin/content/links_manage.htm';
				}
			} else {
				alert(feedback.message);
			}
		});
	});
	
});
